<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;

use App\Models\Serve;
use App\Models\Leimu;
use App\Models\Bnnaer;
use App\Models\Help;
use App\Models\News;
use App\Models\About;

use DB;

class StaticPagesController extends Controller
{
    //banber轮播图
    public function banner(){

    	//取出banner
    	$banner = Bnnaer::select('id','path','href','commit')->get();

    	return ['status'=>'1','banner'=>$banner];
    }


    //获取类目
    public function leimu(){

    	//取出所有类目
    	$leimu = DB::table('class')->select('id','classname')->get();

    	return ['status'=>'1','leimu'=>$leimu];
    }

    //获取类目下服务
    public function class($id){

        //获取类目下的服务
    	$serve = DB::table('leimus')->LeftJoin('serves','leimus.serve_a','=','serves.id')
    							->where('leimus.cid',$id)
    							->select('serves.id','serves.title','serves.commit','serves.path','serves.price','serves.make')
    							->get();
    	// 取出热门服务
    	$remen = DB::table('serve_hot')
    					->LeftJoin('serves','serve_hot.sid','=','serves.id')
    					->select('serves.id','serves.title','serves.path')
    					->get();
       

    	//取出精品推荐
    	$jingpin = DB::table('serve_attach')->get();

        $jingpinfujian = DB::table('jingpin_fujian')->get();
        //声明一个空数存放精品推荐服务
        $jp = array(); 
        $jpin = array();
        foreach($jingpin as $jv){
            foreach($jingpinfujian as $fv){
                if($jv->sid == $fv->sid){

                    $jp['id'] = $jv->id;
                    $jp['sid'] = $jv->sid;
                    $jp['commit'] = $jv->commit;
                    $jp['price'] = $jv->price;
                    $jp['is_price'] = $jv->is_price;
                    $jp['img'][] = $fv->img;
                }
            }

            $jpin[] = $jp;
        }

    	return ['status'=>'1','serve'=>$serve,'remen'=>$remen,'jingpin'=>$jpin];
    }

    //获取所有服务
    public function serves_all(){

        //获取所有服务
        $serve = DB::table('serves')
                        ->select('serves.id','serves.title','serves.commit','serves.price','serves.is_price','serves.path','serves.make')
                        ->OrderBy('id','desc')
                        ->get();
      
        return ['status'=>'1','serve'=>$serve];
    }


    //获取服务详情
    public function serves($id){

    	//取出服务详情
    	$serve = Serve::LeftJoin('serve_contents','serves.id','=','serve_contents.sid')
    			->where('serves.id',$id)
    			->select('serves.id','serves.title','serves.commit','serves.price','serves.vip_price','serve_contents.content','serves.make')
    			->get();

    	//取出服务关联精品推荐
    	$glserves = DB::table('serve_gls')->LeftJoin('serve_attach','serve_gls.gl_sid','=','serve_attach.sid')
    						->where('serve_gls.sid',$id)
    						->select('serve_attach.*')
    						->get();
        //取出精品推荐附件
        $jingpinfujian = DB::table('jingpin_fujian')->get();
         //声明一个空数存放精品推荐服务
        $jp = array(); 
        $jpin = array();
        foreach($glserves as $jv){
            foreach($jingpinfujian as $fv){
                if($jv->sid == $fv->sid){

                    $jp['id'] = $jv->id;
                    $jp['sid'] = $jv->sid;
                    $jp['commit'] = $jv->commit;
                    $jp['price'] = $jv->price;
                    $jp['is_price'] = $jv->is_price;
                    $jp['img'][] = $fv->img;
                }
            }

            $jpin[] = $jp;
        }


        //取出预约详情
        $yuyue = DB::table('notices')->select('id','starttime','stoptime','yuyue','tixing','tishi')->get();

    	return ['status'=>'1','serve'=>$serve,'glserves'=>$jpin,'yuyue'=>$yuyue];
    }


    //服务详情单独接口+预约详情
    public function servesdetails($id){ 

        //取出服务详情
        $content = DB::table('serve_contents')->where('sid',$id)->select('content')->get();
        //取出预约详情
        $yuyue = DB::table('notices')->select('id','starttime','stoptime','yuyue','tixing','tishi')->get();

        return ['status'=>'1','content'=>$content,'yuyue'=>$yuyue];
    }
    //取出app帮助内容
    public function help(){

        //获取帮助所有内容
        $help = Help::select('id',"title","content","created_at")->get();

        return ['status'=>'1','help'=>$help];
    }


    //取出帮助内容详情
    public function helpget($id){

        //当前帮助详情
        $help = Help::select('id',"title","content","created_at")->find($id);

        return ['status'=>'1','help'=>$help];
    }
    //取出推送消息
    public function news($id){

        if($id == 1){

             //获取帮助所有内容
            $news = News::select('id',"title","content","created_at")->get();
            //状态1
            $status = $id;

        }else{

            //状态
            $status = $id;
            //获取空数据
            $news = '';
        }

        return ['status'=>$id,'news'=>$news];
    }


    //获取推送消息详情
    public function newsget($id){

        //获取帮助所有内容
        $news = News::select('id',"title","content","created_at")->find($id);
        
        return ['status'=>1,'news'=>$news];
    }

    //取出关于我们
    public function about(){

        //取出关于我们
        $about = About::select('id','title','content','mobile','QQ','phone','email')->first();

        return ['status'=>1,'about'=>$about];
    }

    //客服接口
    public function kefu(){

        // 返回客服电话  投诉电话 qq号码  iospublic
        $tel = '0830-666666';
        $tstel = '0830-888888';
        $qq = '3528419209';

        //退款理由
        $tuikuan = ['退款理由1','退款理由2','退款理由3'];

        return ['iospublic'=>0,'tel'=>$tel,'tstel'=>$tstel,'qq'=>$qq,'tuikuan'=>$tuikuan];
    }

    //用户会员规则接口
    public function uservipset(){

        //获取会员规则设置
        $uservip = DB::table('vipset')->find(1);


        return ['code'=>1,'vipset'=>$uservip];

    }

}
